package com.neusoft.controller;

import com.neusoft.entity.BanJi;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.util.List;

@RestController
@RequestMapping("banji/consumer")
public class BanjiConsumerController {

    @Autowired
    RestTemplate restTemplate;      //提供一些便利的方法直接访问http请求

    private String url_prefix = "http://provider-banji";    //"http://localhost:8001";

    @RequestMapping("insert")
    public ResponseEntity<Boolean> insert(BanJi bean){
        String url = url_prefix + "/banji/insert";
        return restTemplate.postForEntity(url, bean, Boolean.class);
    }

    @RequestMapping("queryAll")
    public Object queryAll(){
        String url = url_prefix + "/banji/queryAll";
        return restTemplate.getForObject(url, List.class);
    }

    @GetMapping("queryById/{id}")
    public Object queryById(@PathVariable Integer id){
        String url = url_prefix + "/banji/queryById/" + id;
        return restTemplate.getForObject(url,BanJi.class);
    }

}

